//
//  ServiceCategoriesViewController.swift
//
//
//  Created by Ralf on 6/12/15.
//
//

import UIKit

class ServiceCategoriesL1Delegate: NSObject, UICollectionViewDelegate, UICollectionViewDataSource
{
    var secondview:     UICollectionView?
    var secondDelegate: ServiceCategoriesL2Delegate?
    //    let firstCategorysImages      = ["SC-ImageManagement.png", "SC-Creative.png", "SC-Civilization.png", "SC-DreamHome.png", "SC-TasteLife.png", "SC-Technology.png"]
    let firstCategoryTitle        = "为了你的"
    let firstCategorysDiscription = ["形象管理", "创意酷玩", "修养提升", "梦想之家", "品味生活", "科技怪诞"]
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return firstCategorysDiscription.count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell: FirstCategoryCell = collectionView.dequeueReusableCellWithReuseIdentifier("FirstCell", forIndexPath: indexPath) as! FirstCategoryCell
        //        cell.setData(firstCategorysDiscription[indexPath.item], title: firstCategoryTitle, imageName: firstCategorysImages[indexPath.item])
        cell.setData(firstCategorysDiscription[indexPath.item], title: firstCategoryTitle)
        return cell
    }
    
    func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return true
    }
    
    func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return true
    }
    
    func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath)
    {
        let cell = collectionView .cellForItemAtIndexPath(indexPath)
        cell?.backgroundColor = UIColor.whiteColor()
    }
    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
    {
        //        collectionView.reloadData()
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FirstCategoryCell
        //        cell.setShadow(true)
        cell.backgroundColor = UIColor.whiteColor()
        secondDelegate?.dataIndex = indexPath.item
        secondview?.reloadData()
    }
    
    func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)
    {
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FirstCategoryCell
        cell.backgroundColor = UIColor.groupTableViewBackgroundColor()
        //        cell.setShadow(false)
    }
}